<template>
  <div>
    <div class="headr">
      <img src="../../assets/journalism.png" alt="" class="pic" />
    </div>
    <div v-for="item in InfoList" :key="item.id" class="infoList">
      <div class="xinwen" @click="godetail(item.id)">
        <img :src="imgurl + item.cover_image" alt="" class="picture" />
        <div class="right">
          <div class="titl">{{ item.title }}</div>
          <div class="createtime">{{ item.createtime | dateFormat }}</div>
          <div class="content">{{ item.content }}</div>
        </div>
      </div>
    </div>
    <div class="paging">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :page-sizes="[4]"
        :page-size="4"
        layout="total, sizes, prev, pager, next, jumper"
        :total="InfoList.length"
       
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      InfoList: [],
      imgurl: "",
      Total: 0,
      currentPage: 1,
      pagesize: 2,
    };
  },
  created() {
    this.getInfoList(1);
    this.imgurl = this.Imgurl;
  },
  methods: {
    // 获取新闻列表
    async getInfoList(page) {
      const { data: res } = await this.$axios.post("index/getNews",{
        pageSize: 4,
        page:page,
      });
      this.Total = res.data.total
    //   this.paginations.total = res.data.total
      this.InfoList = res.data.data;
      console.log(this.InfoList);
    },
    // 去新闻详情
    godetail(id) {
      this.$router.push({
        path: "/infodetail",
        query: {
          id: id
        }
      });
    },
    handleSizeChange(size) {
        this.pagesize = size
        this.getInfoList(size)
    
    },
    handleCurrentChange(currentPage) {
      //当前是哪一页
      this.currentPage = currentPage
      this.getInfoList(currentPage)
    }
  }
};
</script>

<style lang="scss">
.infoList {
  width: 60%;
  margin: 0 auto;
  padding-top: 2%;
  .xinwen {
    display: flex;
    .picture {
      width: 272px;
      height: 192px;
    }
    .right {
      padding-left: 23px;
      .titl {
        padding-top: 15px;
        font-size: 20px;
      }
      .createtime {
        padding-top: 10px;
        font-size: 14px;
      }
      .content {
        font-size: 14px;
        color: #999999;
        padding-top: 20px;
      }
    }
  }
}
.paging {
  display: flex;
  justify-content: center;
  padding-top: 70px;
}
</style>
